<template>
    <div>
        <!-- 表格表头 -->
        <div class="table-header">
            <div>
                <el-button-group>
                    <el-button icon="el-icon-circle-plus-outline" size="small"
                        @click="selectUserDailog(userRoleForm.roleId)">关联职责</el-button>
                    <el-button icon="el-icon-remove-outline" size="small" @click="deleteHandle()">删除职责</el-button>
                </el-button-group>
            </div>
            <div>
                <el-button size="small" round icon="el-icon-refresh" @click="getRoleRespList()"></el-button>
            </div>
        </div>

        <el-table :data="userroleList" size="small" min-height="300" style="width: 100%" highlight-current-row
            @selection-change="handleSelectionChange">
            <el-table-column type="selection" header-align="center" align="center" width="50">
            </el-table-column>
            <el-table-column property="pkResponsibility" label="职责编号"></el-table-column>
            <el-table-column property="name" label="职责名称"></el-table-column>
            <el-table-column property="typeDesc" label="职责类型"></el-table-column>
            <el-table-column property="description" label="职责描述"></el-table-column>
            <el-table-column property="groupName" label="所属集团"></el-table-column>
            <el-table-column property="orgName" label="所属组织"></el-table-column>
            <el-table-column property="enabledate" label="有效期"></el-table-column>
            <el-table-column property="disabledate" label="失效期"></el-table-column>

            <div slot="empty">
                <div class="avue-empty">
                    <div class="avue-empty__image" style="height: 50px;"><img
                            src=""
                            alt=""></div>
                    <p class="avue-empty__desc">暂无数据</p>
                </div>
            </div>
        </el-table>

        <!--选择用户弹出框  -->
        <resp-dailog v-if="usergroupVisible" ref="respdailog" @refreshDataList="getRoleRespList"></resp-dailog>
    </div>

</template>
<script>
    // 职责选择框
    import RespDailog from './dailog/resp-dailog'

    import * as responsibilityService from '@/api/upms/responsibility'
    export default {
        data() {
            return {
                userRoleForm: {
                    roleId: ''
                },
                userroleList: [],
                usergroupVisible: false,
                multipleSelection: []
            }
        },
        components: {
            RespDailog,
        },
        methods: {
            init(roleId) {
                if (roleId) {
                    this.userRoleForm.roleId = roleId;
                    this.getRoleRespList()
                }
            },
            // 默认加载某个角色职责授权列表
            getRoleRespList() {
                responsibilityService.getresponsibilityselectedlist(this.userRoleForm.roleId).then(data => {
                    this.userroleList = data
                })
            },
            //多选
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            // 弹框选择用户
            selectUserDailog(id) {
                this.usergroupVisible = true
                this.$nextTick(() => {
                    this.$refs.respdailog.init(id)
                })
            },
            // 删除
            deleteHandle(id) {
                var ids = id ? [id] : this.multipleSelection.map(item => {
                    return item.pkRoleResp
                })
                var names = this.multipleSelection.map(item => {
                    return item.name
                })

                this.$confirm(`确定对[${names.join(',')}]进行删除操作?`, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    responsibilityService.delBatchroleresp(ids).then(data => {
                        this.$message({
                            message: '操作成功',
                            type: 'success',
                            duration: 1500,
                            onClose: () => {
                                this.getRoleRespList()
                            }
                        })
                    })
                }).catch(() => {})
            }
        }
    }
</script>